﻿using Microsoft.AspNetCore.Mvc;
using QntPlatform;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace QntSvc.Web.Controllers
{
    [Route("uapi/[controller]/[action]")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserDataController : ControllerBase
    {
      static  IDictionary<string, string> appData = new ConcurrentDictionary<string, string>();
        ILog log = new RobotLog(0); // Log.GetLogger("UserData");
        /// <summary>Binance:BTCUSDT:60
        /// key  :     $"{Exchange.Name}:{Exchange.Currency}:{NowPeriod}"
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void SetUserData(string key,string value) {
            //Console.WriteLine($"设置用户数据：{key},{value}");
            log.Info($"设置用户数据：{key},{value}");
            if (appData.ContainsKey(key))
            {
                appData[key] = value;
            }else
            appData.Add(key, value);
        }
        [HttpGet]

        public string GetUserData(string key) {
            if (appData.TryGetValue(key,out var value))
            {
                return value;
            }
            return null;
        }
    }
}
